<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 相册模块
 */
class Photo extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';


    /**
     *
     * 相册列表
     */
    public function index()
    {
        $user_id = $this->uid;
        if(input('user_id') && !empty(input('user_id'))){
            $user_id = input('user_id');
        }
        $this->success('成功', model('photo')->where('user_id', $user_id)
            ->field('id,photo')->order('id desc')->paginate(10));
    }

    /**
     *
     * 添加相册
     */
    public function add()
    {
        $param = input();
        $param['user_id'] = $this->uid;
        $data = explode(',', input('photo'));
        foreach ($data as $v) {
            $param['photo'] = $v;
            \app\api\model\Photo::create($param);
        }
        $this->success('成功');
    }

    /**
     *
     * 删除相册
     */
    public function del()
    {
        $this->success('成功', \app\api\model\Photo::destroy(input('photo_id')));
    }
}